import { Vechile, Car, Bus } from "../extendsdemo/demo1";

// 泛型接口 泛型约束 多态的应用
class Customer {
  //  public  rentVechile(vechile:Vechile){
  //       vechile.calculateRent();
  //  }
  //public rentVechile1(vechile: (Bus |Car )[]) {
  public rentVechile(myVechileArray: Vechile[]) {
    let total: number = 0;
    myVechileArray.forEach((vechile) => {
      total += vechile.calculateRent();
    });
    return total;
  }
}


//一个父类数组对象变量的每一个元素都可以接受任何一个该父类的子类对象
let vechileArray: Vechile[] = [];
//let vechileArray: (Car | Bus | Truck)[] = []
vechileArray[0] = new Bus("大巴", "京3A556", 3, 50000, 67);
vechileArray[1] = new Car("大卡车", "京7A556", 2, 60000, "兰博基尼");
let cust = new Customer();
let lasttotal = cust.rentVechile(vechileArray);
console.log("lasttotal:", lasttotal);

// 一次租多辆车
//new Bus("大巴", "京3A556", 3, 50000, 67));
//new Truck("大卡车", "京7A556", 2, 60000, 1500);

export {};
